package cn.lanqiao.book.controller;


import cn.lanqiao.book.service.impl.UserServiceImpl;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/*
* 用于过滤发送验证码请求
* 验证用户名和邮箱是否匹配
* param username 用户名
* param email 邮箱
*
* */
@WebFilter("/sendVerification")
public class IsCorrectEmail extends HttpFilter {
    @Override
    protected void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterChain chain) throws IOException, ServletException {
        resp.setContentType("text/html;charset=UTF-8");
        String username=req.getParameter("username");
        String email=req.getParameter("email");
        if(UserServiceImpl.getInstance().checkEmail(username,email)){
            //如果邮箱正确，那么开始发送验证码
            chain.doFilter(req,resp);
        }else {
            resp.getWriter().write("邮箱地址错误");
        }
    }
}
